package com.lk.recvice.server;

import com.lk.base.mysql.domain.TblDevices;
import io.netty.channel.socket.SocketChannel;

import java.util.*;

public class MyServerSocket {

	//存储了socket长连接信息的集合
	public static  Map<String, MySocketChannel> socketChannel_keepalive = new HashMap<>();

	public static List<MySocketChannel> socketChannelList_keepalive = new LinkedList<>();
	public static Map<String,String> strMap = new Hashtable<>();

	public static Map<String ,List<String>> deviceMaps = new HashMap<>();

	public static Map<String ,String> deviceProjectMaps = new HashMap<>();


	public static Map<String, String> snFindIpMap = new HashMap<>();

	public static Map<String, TblDevices> gasMaps = new HashMap<>();


	/**
	 * 移除socket连接
	 * @param channelId
	 * @return
	 */
	public static boolean removeMySocketChannel_keepalive(String channelId) {

		MyServerSocket.socketChannel_keepalive.remove(channelId);
		new Thread(new Runnable() {

			@Override
			public void run() {
				List<MySocketChannel> list = MyServerSocket.socketChannelList_keepalive;

				for (Iterator<MySocketChannel> dd = list.iterator(); dd.hasNext();) {
					MySocketChannel mySocketChannel = dd.next();
					SocketChannel socketChannel = mySocketChannel.getSocketChannel();
				    if (socketChannel.id().toString().equals(channelId)) {
				    	dd.remove();
				    }
				}
			}
		}).start();

		return true;
	}


}
